import 'package:eshi/app/shi/widget/BaseTextWidget.dart';
import 'package:eshi/app/shi/widget/CommonWidgets.dart';
import 'package:eshi/app/shi/widget/VideoPlayBox.dart';
import 'package:flutter/material.dart';
import 'package:eshi/app/shi/data/parse/FileParser.dart';

/// 视频播放组件
class VideoWidget extends StatefulWidget {
  final String text;
  final Widget child;
  final showChild;
  final hasBackButon;
  String videoAssetPath="";  // 音频资源路径，如 'assets/audio/example.mp3'
  TextStyle? style;
  
  VideoWidget({super.key,required this.text, required this.child, this.showChild = true, this.hasBackButon=false}){
      videoAssetPath = FileParser.getWholeName("assets/video/",text);
  }
  @override
  VideoWidgetState createState() => VideoWidgetState();
}

class VideoWidgetState extends State<VideoWidget> {

  @override
  Widget build(BuildContext context) {
    return MarkBuild(
      children:  widget.showChild ? widget.child : null, 
      page: videoPlay,
      dialog: () async{
        await simpleDialog(
          context: context, 
          body: VideoWidget(text: widget.text,showChild: false,hasBackButon:true, child: widget.child),
          // title : widget.text
        );
      },
      icon:Icons.video_chat,
      type: "video",
      name: widget.text
    ).create();
  }

  Widget videoPlay([bool isBaseBox=false]){
    var w = MediaQuery.of(context).size.width;
    if(!isBaseBox && widget.hasBackButon){
        Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                IconButton(
                  icon: const Icon(Icons.arrow_back, color: Colors.white),
                  onPressed: () => Navigator.pop(context),
                ),
              ]
            ),
            videoPlay(true)
      ]);
    }
    return SizedBox(width: w,height: w/4*3,
      child:  VideoPlayBox(videoUrl:widget.videoAssetPath)
    );
  }
}